package app.server.project.main.service.db.dao.user;

import app.server.project.main.service.bo.dbquery.WithDrawParam;
import app.server.project.main.service.db.entity.user.UserWithDrawDetailEntity;
import app.server.project.main.service.db.mapper.user.UserWithDrawDetailMapper;
import app.server.project.main.service.service.race.CoinType;
import app.server.project.main.service.service.withdraw.WithDrawStatus;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【user_info(用户信息表)】的数据库操作Service实现
 * @createDate 2025-01-16 15:25:22
 */
@Repository
public class UserWithDrawDetailDao extends ServiceImpl<UserWithDrawDetailMapper, UserWithDrawDetailEntity> {


    public IPage<UserWithDrawDetailEntity> getAllByParam(WithDrawParam withDrawParam) {
        Page<UserWithDrawDetailEntity> page = Page.of(withDrawParam.getPageIndex(), withDrawParam.getPageSize());
        LambdaQueryWrapper<UserWithDrawDetailEntity> query = Wrappers.lambdaQuery();
        if (withDrawParam.isBTC()) {
            query.eq(UserWithDrawDetailEntity::getRaceId, CoinType.BTC_COIN);
        } else {
            query.ne(UserWithDrawDetailEntity::getRaceId, CoinType.BTC_COIN);
        }
        query.eq(UserWithDrawDetailEntity::getStatus, withDrawParam.getStatus());
        query.orderByDesc(UserWithDrawDetailEntity::getVal);
        return this.page(page, query);
    }


    public void pass(List<Long> ids) {
        ids.forEach(v -> {
            this.update(Wrappers.<UserWithDrawDetailEntity>lambdaUpdate()
                    .set(UserWithDrawDetailEntity::getStatus, WithDrawStatus.Pass)
                    .set(UserWithDrawDetailEntity::getPassTime, LocalDateTime.now())
                    .eq(UserWithDrawDetailEntity::getId, v));
        });
    }

    public void reject(List<Long> ids) {
        ids.forEach(v -> {
            this.update(Wrappers.<UserWithDrawDetailEntity>lambdaUpdate()
                    .set(UserWithDrawDetailEntity::getStatus, WithDrawStatus.Reject)
                    .set(UserWithDrawDetailEntity::getPassTime, LocalDateTime.now())
                    .eq(UserWithDrawDetailEntity::getId, v));
        });
    }

    public List<UserWithDrawDetailEntity> getDataById(List<Long> ids) {
        return this.list(Wrappers.<UserWithDrawDetailEntity>lambdaQuery().in(UserWithDrawDetailEntity::getId, ids));
    }
}




